<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">
	<ui:define name="corpo">

		<h:form id="formAula">
			<p:growl id="growl" life="2500"></p:growl>
			<p:dialog header="Detalhes" widgetVar="dialogAula" modal="true">
				<p:outputPanel id="gridAula" style="text-align:center;"
					layout="block">


					<p:panelGrid columns="2">

						<h:outputLabel for="prof" value="Professor: " />
						<h:outputText id="prof"
							value="#{aulaBean.aula.competencia.professor.usuario.nome}" />

						<h:outputLabel for="disciplina" value="Disciplina: " />
						<h:outputText id="disciplina"
							value="#{aulaBean.aula.competencia.disciplina.nome}" />

						<h:outputLabel for="dia" value="Dia: " />
						<h:outputText id="dia"
							value="#{aulaBean.aula.disponibilidade.dia.dia}" />

						<h:outputLabel for="hor" value="Horario: " />
						<h:outputText id="hor"
							value="#{aulaBean.aula.disponibilidade.horario}" />

						<h:outputLabel for="tur" value="Turno: " />
						<h:outputText id="tur"
							value="#{aulaBean.aula.disponibilidade.turno}" />

						<h:outputText value="Disciplina: "
							rendered="#{aulaBean.auxiliarAula != '2'}" />
						<p:autoComplete id="selectCompetencia" converter="disciplinaConverter"
							value="#{aulaBean.aula.competencia.disciplina}"
							completeMethod="#{aulaBean.completaNomeDisciplina}" var="c"
							itemLabel="#{c.nome}" itemValue="#{c}"
							forceSelection="true" dropdown="true"
							rendered="#{aulaBean.auxiliarAula != '2'}" />

						<p:commandLink actionListener="#{aulaBean.grava}"
							title="Cadastrar" update=":formDatagrid :formImpressao growl"
							oncomplete="lidaCadastroAula(xhr, status, args)"
							rendered="#{aulaBean.auxiliarAula != '2'}">
							<p:graphicImage value="resources/imagens/ok.png"></p:graphicImage>
						</p:commandLink>



						<f:facet name="footer">
							<h:outputText value="Período indisponível para cadastro de aula"
								rendered="#{aulaBean.auxiliarAula == '2'}" />
						</f:facet>

						<script type="text/javascript">
							function lidaCadastroAula(xhr, status, args) {
								if (args.validationFailed || !args.gravado) {
									jQuery('dialogAula').effect("shake", {
										times : 3
									}, 100);
								} else {

									dialogAula.hide();
								}
							}
						</script>


					</p:panelGrid>
				</p:outputPanel>
			</p:dialog>



		</h:form>

		<h:form id="formSelectProfessor">
			<h2>Grade horária</h2>
			<p:commandButton onclick="wPrint.show()" value="Visualizar impressão"
				id="btImprimir" disabled="#{empty aulaBean.aulasMat1}"
				title="selecione um professor" />
			<br></br>
			<br></br>
			<h:panelGrid columns="3">


				<h:outputLabel value="Professor: " />
				<p:autoComplete value="#{aulaBean.competencia.professor}"
					id="completeProf"
					completeMethod="#{aulaBean.completaNomeProfessor}" var="professor"
					itemLabel="#{professor.usuario.nome}#{professor.usuario.sobrenome}#{professor.usuario.matricula}"
					itemValue="#{professor}" converter="professorConverter"
					forceSelection="true" size="45" dropdown="true">

					<p:ajax event="itemSelect"
						listener="#{aulaBean.preencheCompetencias}" />

					<p:ajax event="itemSelect"
						update=":formDatagrid :formImpressao btImprimir"
						listener="#{aulaBean.obterAulas}" />

				</p:autoComplete>
				<p:watermark for="completeProf"
					value="Digite o nome ou matricula para pesquisar"
					rendered="#{not empty professorBean.professores}"></p:watermark>

				<p:watermark for="completeProf"
					value="Nenhum professor cadastrado, favor incluir"
					rendered="#{empty professorBean.professores}"></p:watermark>


			</h:panelGrid>


		</h:form>


		<h:form id="formDatagrid">

			<p:panelGrid style="margin-top:20px" id="grid">

				<f:facet name="header">
					<p:row>
						<p:column colspan="8" style="text-align:center;font-size:22px;">Grade do Professor</p:column>
					</p:row>
				</f:facet>
				<f:facet name="footer">
					<p:row>
						<p:column colspan="8">
							<div style="font-size: medium;">
								<h:outputLabel value="Nome:" for="inputNome" />
								<b><h:outputText id="inputNome"
										value="#{aulaBean.competencia.professor.usuario.nome} #{aulaBean.competencia.professor.usuario.sobrenome}"
										readonly="true" /></b><br />
								<h:outputLabel value="Matrícula" for="inputMatricula" />
								<b><h:outputText id="inputMatricula"
										value="#{aulaBean.competencia.professor.usuario.matricula}"
										readonly="true" /></b>
							</div>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;">  
                Turno  
            			</p:column>
						<p:column style="text-align: center;">  
                Horario	  
            			</p:column>
						<p:column colspan="6">
							<p:dataGrid id="teste01" var="todosDias" value="#{aulaBean.dias}"
								columns="6" style="border: none;"
								emptyMessage="Selecione um professor">
								<p:column>


									<div align="center" style="width: 96px; color: black">
										#{todosDias}</div>

								</p:column>
							</p:dataGrid>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;" rowspan="2">  
               Matutino   
            </p:column>
						<p:column style="text-align: center;">
					1º
				</p:column>
						<p:column colspan="6">
							<p:dataGrid id="gridMatutino1" var="varMatutino1"
								value="#{aulaBean.aulasMat1}" columns="6" style="border: none;"
								emptyMessage="Selecione um professor">
								<p:column>

									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino1.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											#{varMatutino1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino1.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 96px; color: red">
											#{varMatutino1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino1.competencia.disciplina.nome != 'Indisponível' 
										and varMatutino1.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varMatutino1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>

								</p:column>

							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align: center;">
						2º
						</p:column>

						<p:column colspan="6">
							<p:dataGrid id="gridMatutino2" var="varMatutino2"
								value="#{aulaBean.aulasMat2}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column>

									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino2.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											#{varMatutino2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino2.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 96px; color: red">
											#{varMatutino2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino2.competencia.disciplina.nome != 'Indisponível' 
										and varMatutino2.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varMatutino2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>


								</p:column>


							</p:dataGrid>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;" rowspan="2">  
                Noturno  
            </p:column>
						<p:column style="text-align: center;">
					1º
				</p:column>
						<p:column colspan="6">
							<p:dataGrid id="gridNoturno1" var="varNoturno1"
								value="#{aulaBean.aulasNot1}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column
									rendered="#{!aulaBean.isSabado(varNoturno1.disponibilidade.dia)}">

									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno1.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											#{varNoturno1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno1.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 96px; color: red">
											#{varNoturno1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno1.competencia.disciplina.nome != 'Indisponível' 
										and varNoturno1.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varNoturno1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>


								</p:column>
								<p:column
									rendered="#{aulaBean.isSabado(varNoturno1.disponibilidade.dia)}">
									<p:commandLink>
										<div style="width: 96px"></div>
									</p:commandLink>
								</p:column>

							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align: center;">
						2º
						</p:column>

						<p:column colspan="6">
							<p:dataGrid id="gridNoturno2" var="varNoturno2"
								value="#{aulaBean.aulasNot2}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column
									rendered="#{!aulaBean.isSabado(varNoturno2.disponibilidade.dia)}">
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno2.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											#{varNoturno2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno2.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 96px; color: red">
											#{varNoturno2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno2.competencia.disciplina.nome != 'Indisponível' 
										and varNoturno2.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varNoturno2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
								</p:column>
								<p:column
									rendered="#{aulaBean.isSabado(varNoturno2.disponibilidade.dia)}">
									<div style="width: 96px"></div>
								</p:column>
							</p:dataGrid>
						</p:column>
					</p:row>
				</f:facet>
			</p:panelGrid>
		</h:form>
		<h:form id="formImpressao">
			<p:dialog widgetVar="wPrint" id="idPrint" modal="true"
				resizable="false">


				<p:commandButton value="Imprimir" ajax="false">
					<p:printer target="grid"></p:printer>
				</p:commandButton>

				<p:panelGrid id="grid">

					<p:row>
						<p:column colspan="8">
							<div id="cabecalho">
								<h:graphicImage library="imagens" name="logo.gif"
									id="logoCompany" />
							</div>
						</p:column>
						<p:column rowspan="9">

						</p:column>
					</p:row>

					<p:row>
						<p:column colspan="8" style="text-align:center;font-size:22px;">Grade do Professor</p:column>
					</p:row>

					<p:row>
						<p:column colspan="8" style="font-size:16px;">
							<h:outputLabel value="Nome:" for="inputNome" />
							<b><h:outputText id="inputNome"
									value="#{aulaBean.competencia.professor.usuario.nome} #{aulaBean.competencia.professor.usuario.sobrenome}"
									readonly="true" /></b>
							<br />
							<h:outputLabel value="Matrícula" for="inputMatricula" />
							<b><h:outputText id="inputMatricula"
									value="#{aulaBean.competencia.professor.usuario.matricula}"
									readonly="true" /></b>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;">  
                Turno  
            			</p:column>
						<p:column style="text-align: center;">  
                Horario	  
            			</p:column>

						<p:column colspan="6">
							<p:dataGrid id="teste01" var="todosDias" value="#{aulaBean.dias}"
								columns="6" style="border: none;"
								emptyMessage="Selecione um professor">
								<p:column>


									<div align="center" style="width: 96px; color: black">
										#{todosDias}</div>

								</p:column>
							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>

						<p:column style="text-align: center;" rowspan="2">  
               Matutino   
            </p:column>
						<p:column style="text-align: center;">
					1º
				</p:column>
						<p:column colspan="6">
							<p:dataGrid id="gridMatutino1" var="varMatutino1"
								value="#{aulaBean.aulasMat1}" columns="6" style="border: none;"
								emptyMessage="Selecione um professor">
								<p:column>

									<p:commandLink
										rendered="#{varMatutino1.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											Vago</div>
									</p:commandLink>
									<p:commandLink update=":formAula:gridAula"
										rendered="#{varMatutino1.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varMatutino1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>

								</p:column>

							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align: center;">
						2º
						</p:column>

						<p:column colspan="6">
							<p:dataGrid id="gridMatutino2" var="varMatutino2"
								value="#{aulaBean.aulasMat2}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column>

									<p:commandLink
										rendered="#{varMatutino2.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											Vago</div>
									</p:commandLink>
									<p:commandLink update=":formAula:gridAula"
										rendered="#{varMatutino2.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varMatutino2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>


								</p:column>


							</p:dataGrid>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;" rowspan="2">  
                Noturno  
            </p:column>
						<p:column style="text-align: center;">
					1º
				</p:column>
						<p:column colspan="6">
							<p:dataGrid id="gridNoturno1" var="varNoturno1"
								value="#{aulaBean.aulasNot1}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column
									rendered="#{!aulaBean.isSabado(varNoturno1.disponibilidade.dia)}">

									<p:commandLink
										rendered="#{varNoturno1.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											Vago</div>
									</p:commandLink>
									<p:commandLink update=":formAula:gridAula"
										rendered="#{varNoturno1.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varNoturno1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>


								</p:column>
								<p:column
									rendered="#{aulaBean.isSabado(varNoturno1.disponibilidade.dia)}">
									<p:commandLink>
										<div style="width: 96px"></div>
									</p:commandLink>
								</p:column>

							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align: center;">
						2º
						</p:column>

						<p:column colspan="6">
							<p:dataGrid id="gridNoturno2" var="varNoturno2"
								value="#{aulaBean.aulasNot2}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column
									rendered="#{!aulaBean.isSabado(varNoturno2.disponibilidade.dia)}">
									<p:commandLink
										rendered="#{varNoturno2.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											Vago</div>
									</p:commandLink>
									<p:commandLink update=":formAula:gridAula"
										rendered="#{varNoturno2.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varNoturno2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
								</p:column>
								<p:column
									rendered="#{aulaBean.isSabado(varNoturno2.disponibilidade.dia)}">
									<div style="width: 96px"></div>
								</p:column>




							</p:dataGrid>
						</p:column>
					</p:row>

				</p:panelGrid>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>

</html>